/**
 * 防抖
 * @param {*} fn 
 * @param {*} time 
 */
export function debounce (fn, time) {
  let _arguments = arguments
  let timeout = null
  return function() {
    if(timeout){
      clearTimeout(timeout)
    }
    timeout = setTimeout(() => {
      fn.call(this, _arguments)
    }, time)
  }
}

/**
 * 节流
 * @param {*} fn 
 * @param {*} time 
 */
export function throttle (fn, time) {
  let _arguments = arguments
  let canRun = true
  return function() {
    if(!canRun){
      return 
    }
    canRun = false
    setTimeout(() => {
      fn.call(this, _arguments);
      canRun = true
    }, time);
  }
}
